package servlet;

import data.CountRecordData;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "CountServlet")
public class CountServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setHeader("Content-Type", "text/html");
        response.setCharacterEncoding("UTF-8");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        String operator = request.getParameter("operator");
        String table = request.getParameter("table");
        String responseText = "";
        CountRecordData countRecordData = new CountRecordData(start, end, operator);
        switch (table) {
            case "1"://加密
                responseText = countRecordData.countEncryptionData();
                break;
            case "2"://解密
                responseText = countRecordData.countDecryptionData();
                break;
            case "3"://验证
                responseText = countRecordData.countVerificationData();
                break;
            case "4"://签名
                responseText = countRecordData.countSignatureData();
                break;
            case "5"://签密
                responseText = countRecordData.countSigncryptionData();
                break;
            case "6"://解签密
                responseText = countRecordData.countUnsigncryptionData();
                break;
            case "7"://MAC
                responseText = countRecordData.countMacData();
                break;
            case "8"://认证加密
                responseText = countRecordData.countAEData();
                break;
            case "9"://解密验证
                responseText = countRecordData.countDVData();
                break;
            default:
        }
        PrintWriter printWriter = response.getWriter();
        printWriter.print(responseText);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        doPost(request, response);
    }
}
